/**
 * @file   shared_memory.hpp
 * @author wolfhead <wolfhead@wolfhead-laptop>
 * @date   Thu Oct 27 16:21:57 2011
 * 
 * @brief  
 * 
 * 
 */
#ifndef ACAPELLA_UTIL_SHARED_MEMORY_HPP
#define ACAPELLA_UTIL_SHARED_MEMORY_HPP

#include "../shared_ptr.hpp"

namespace acapella
{
namespace util
{

class SharedMemory
{
public:
    typedef unsigned char ContentType;
    typedef shared_ptr<ContentType, ArrayPointerContent> MemoryPtr; 

    SharedMemory& alloc(size_t size)
    {
        pMemory_ = MemoryPtr(new ContentType[size]);
        size_ = size;
        return *this;
    }

    size_t size() const 
    {
        return size_;
    }

    const ContentType * get() const
    {
        return (const ContentType *)pMemory_.get();
    }

    ContentType * get()
    {
        return (ContentType *)pMemory_.get();
    }

    operator const ContentType * () const
    {
        return get();
    }

    operator ContentType * ()
    {
        return get();
    }

private:
    MemoryPtr pMemory_;
    size_t size_;
};

}//namepsace util
}//namespace acapella

#endif
